package ferus.tigris.lines.levels;

import java.util.List;

import android.graphics.Point;
import android.util.Log;
import ferus.tigris.lines.GameManager;
import ferus.tigris.lines.data.PersonageInfo;
import ferus.tigris.lines.personages.AbstractBehavior;

public class LevelManager {
	private AbstractLevel level;
	private GameManager gameManager;
	public LevelManager(GameManager gameManager) {
		this.gameManager = gameManager;
		level = startGameLevel();
	}

	protected StaticLevel startGameLevel() {
		return new StaticLevel(this, gameManager, 0, 100);
	}

	public void start() {
		Log.d(getClass().toString(), "start");
		level.start();
	}

	public void setLevel(AbstractLevel newLevel) {
		Log.d(getClass().toString(), "setLevel " + newLevel.getClass().toString());
		level = newLevel;
	}

	public void complite() {
		Log.d(getClass().toString(), "complite");
		gameManager.playLevelCompliteSound();
		setLevel(level.nextLevel());
		level.start();
	}

	public void fail() {
		Log.d(getClass().toString(), "fail");
		gameManager.playLevelFailSound();
		gameManager.onLevelFail();
		setLevel(startGameLevel());
		level.start();
	}

	public int check() {
		return level.check();
	}
	
	public void died(AbstractBehavior personage) {
		level.died(personage);
	}

	public void onTouch(Point p) {
		level.onTouch(p);
	}

	public double scopeScale() {
		return level.scaleScope();
	}

	public void load(String loadLevel, int scope, int complexity) {
		if(loadLevel.contains("StaticLevel")) {
			setLevel(new StaticLevel(this, gameManager, scope, complexity));
		} else
		if(loadLevel.contains("LevelWithRandomInit")) {
			setLevel(new LevelWithRandomInit(this, gameManager, scope, complexity));
		} else
		if(loadLevel.contains("LevelWithNullInit")) {
			setLevel(new LevelWithNullInit(this, gameManager, scope, complexity));
		} else {
			setLevel(new StaticLevel(this, gameManager, scope, complexity));
		}
	}

	public String levelType() {
		if(level != null)return level.getClass().toString();
		return "";
	}

	public void fill(List<PersonageInfo> personages) {
		level.fill(personages);
		level.onLoad();
	}

	public List<PersonageInfo> personages() {
		return level.personages();
	}

	public int scope() {
		return level.scope();
	}

	public int complexity() {
		return level.complexity();
	}

}
